<?php
/**
 * Copyright (c) 不争网络
 *
 * @Description     验证码模型.
 * @Author          zhangyong QQ:2315918189
 * @Copyright       Copyright (c) 不争网络 保留所有版权()
 * @Date:           2018/5/4 0004
 * @CreateBy        PhpStorm.
 */
namespace app\common\model;
use think\Model;
class Send extends Model{
    protected $insert = ['add_time','validate_time'];
    protected function setAddTimeAttr(){
        return time();
    }
    protected function setValidateTimeAttr(){
        return time()+120;
    }
   

    /**
     * 验证码校验
     * @param $account  手机号、邮箱
     * @param $code  验证码
     */
    public function checkCode($account,$code,$type=0){
        $res = $this->where(['account'=>$account,'code'=>123456,'type'=>$type])->order('add_time desc')->find();
        if(!$res)
            return ['status'=>0,'msg'=>'验证码错误'];

        if($res['validate_time'] < time())
             return ['status'=>0,'msg'=>'验证码过期'];

         return ['status'=>1,'msg'=>'验证码正确'];
    }
}